﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace DART.Detector.IRay
{

    /// <summary>
    /// 带自动通知的探测器计数器
    /// </summary>
    public class DetectorCounter : IDetectorCounter
    {
        private int exposureCount;

        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        public int ExposureCount
        {
            get { return exposureCount; }
            set { SetProperty(ref exposureCount, value); }
        }

        private int imageCount;

        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        public int ImageCount
        {
            get { return imageCount; }
            set { SetProperty(ref imageCount, value); }
        }

        private int sequenceIndex;

        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        public int SequenceIndex
        {
            get { return sequenceIndex; }
            set { SetProperty(ref sequenceIndex, value); }
        }

        private int sequenceCount;
        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        public int SequenceCount
        {
            get { return sequenceCount; }
            set { SetProperty(ref sequenceCount, value); }
        }

        private int sequenceExposureCount;
        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        public int SequenceExposureCount
        {
            get { return sequenceExposureCount; }
            set { SetProperty(ref sequenceExposureCount, value); }
        }

        private int sequenceImageCount;
        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        public int SequenceImageCount
        {
            get { return sequenceImageCount; }
            set { SetProperty(ref sequenceImageCount, value); }
        }
        /// <summary>
        /// 创建副本
        /// </summary>
        /// <returns></returns>
        public DetectorCounter Clone() => MemberwiseClone() as DetectorCounter;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(storage, value)) return false;

            storage = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

            return true;
        }
    }

    /// <summary>
    /// 探测器计数器(只读，带通知)
    /// </summary>
    public interface IDetectorCounter : INotifyPropertyChanged
    {
        /// <summary>
        /// 曝光计数(预曝光+主曝光) [1,<see cref="int.MaxValue"/>)
        /// </summary>
        int ExposureCount { get; }

        /// <summary>
        /// 主曝光计数 [1,<see cref="int.MaxValue"/>)
        /// </summary>
        int ImageCount { get; }

        /// <summary>
        /// 当前序列索引编号 [0,<see cref="int.MaxValue"/>)
        /// </summary>
        /// <remarks>Combo，Stereo等采集模式可能存在两组图像序列</remarks>
        int SequenceIndex { get; }

        /// <summary>
        /// 已完成序列计数 [1,<see cref="int.MaxValue"/>)
        /// </summary>
        int SequenceCount { get; }

        /// <summary>
        /// 当前序列曝光计数(预曝光+主曝光) [1,<see cref="int.MaxValue"/>)
        /// </summary>
        int SequenceExposureCount { get; }

        /// <summary>
        /// 当前序列主曝光计数 [1,<see cref="int.MaxValue"/>)
        /// </summary>
        int SequenceImageCount { get; }
    }

}